package main
 
import (
  "database/sql"
  _ "github.com/go-sql-driver/mysql"
  "log"
  //"time"
)
 
func insert(db *sql.DB) {
  stmt, err := db.Prepare("INSERT INTO gbccase_url(gbc_y, gbc_id,account) VALUES(?, ?,?)")
  defer stmt.Close()
 
  if err != nil {
    log.Println(err)
    return
  }
  ret,err := stmt.Exec("16", "100","")
  log.Println(ret)

  if err != nil{
    log.Println(err)
    return
  }
  stmt.Exec("17", "200","")
 
}
 
func main() {
  db, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/istore2")
  if err != nil {
    log.Fatalf("Open database error: %s\n", err)
  }
  defer db.Close()
 
  log.Println("db open")
  err = db.Ping()
  if err != nil {
    log.Fatal(err)
  }
 
  insert(db)
 
  //<-time.After(time.Second * 10)
  rows, err := db.Query("select gbc_id,gbc_y from gbccase_url where gbccase_id = ?", 1)
  if err != nil {
    log.Println("sql err",err)
  }
 
  defer rows.Close()
  var id int
  var y string
  //var dd map[string]interface{}
  //dd = map[string]interface{}{"id":0,"y":0}

  for rows.Next() {
    err := rows.Scan(&id,&y)
    if err != nil {
      log.Fatal("set err",err)
    }
    log.Println(id,y)
  }
 
  err = rows.Err()
  if err != nil {
    log.Fatal("err1",err)
  }
}